﻿@page
@model SunuerManage.Pages.Manage.Admins.AdminPassWordModel
@{
}

<!-- 基本信息 -->
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input class="layui-input" name="AdminName" type="text" value="@Model.Model.AdminName" disabled="disabled">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-inline">
            <input name="AdminNick" class="layui-input" type="text" placeholder="昵称" value="@Model.Model.AdminNick" disabled="disabled">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">原始密码</label>
        <div class="layui-input-inline">
            <input name="OldPass" class="layui-input" type="password" lay-verify="required" placeholder="原始密码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input name="Pass" class="layui-input pass" type="password" lay-verify="required" placeholder="新密码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-inline">
            <input name="Passs" class="layui-input passs" type="password" lay-verify="required|Pass" placeholder="确认新密码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" class="layui-btn btn" id="layuiadmin-app-form-submit" value="确认修改">
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '/js/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
        , form = layui.form;
        form.verify({
            Pass: function (value, item) { //value：表单的值、item：表单的DOM对象
                if ($('.passs').val() != $('.pass').val()) {
                    return '两次密码不同，请确认';
                }
            }

        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = layer.load();
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.ajax({
                url: "/api/Admin/PassWord",
                type: "post",
                async: false,
                data: { OldPass: data.field.OldPass, Pass: data.field.Pass },
                success: function (datas) {
                    if (0 == datas.code) {
                        layer.msg(datas.msg, {
                            icon: 1,
                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                        }, function() {
                            location.reload();
                            layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.msg(datas.msg, {
                            icon: 1,
                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                        }, function() {
                            layer.closeAll();
                        });
                    }
                },
                error: function (e) {
                    layer.closeAll();
                    alert("错误！！");
                }
            });
        });
    })
</script>